<template>
  <div class="search-from flex justify-between">
    <el-form :inline="true" :model="searchFrom">
      <el-form-item label="一级指标：">
        <el-select v-model="searchFrom.indexOne" clearable placeholder="请选择一级指标">
          <el-option v-for="item in indexOneArr" :key="item.name" :label="item.name" :value="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级指标：">
        <el-input v-model="searchFrom.indexTwo" clearable placeholder="二级指标"></el-input>
      </el-form-item>
      <el-form-item label="三级指标：">
        <el-input v-model="searchFrom.indexThree" clearable placeholder="三级指标"></el-input>
      </el-form-item>
      <el-form-item label="质控点：">
        <el-input v-model="searchFrom.name" clearable placeholder="质控点"></el-input>
      </el-form-item>
      <el-form-item :label="organize+'：'" prop="belongPart">
        <el-select v-model="searchFrom.belongPart" filterable clearable :placeholder="'请选择'+organize">
          <el-option :label="item.orgName" :value="item.id" v-for="item in organizeArr" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <slot name="handle"></slot>
        <el-button v-if="checkShow" type="primary" @click="handleCheck()">确认标准值</el-button>
        <!-- <el-button type="primary" plain @click="addPoint()">添加质控点</el-button> -->
        <!--<el-button type="primary" plain @click="goBack"><< 返回</el-button>-->
      </el-form-item>
      <el-form-item v-show="levelType" v-permission="{type:levelType,per:[284,286,287,288,289,290,291,292,293]}">
        <el-button @click="showTemplateDialog" type="primary" plain>导入质控点</el-button>
      </el-form-item>
      <el-form-item v-show="levelType" v-permission="{type:levelType,per:[284,286,287,288,289,290,291,292,293]}">
        <el-link @click="downloadTemplate" type="primary" :underline="false">导入质控点模板下载</el-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getStorage } from '@/config/utils'
import { getAllOrganize } from '@/api/systemManage'

export default {
  name: 'listSearch',
  props: {
    levelType: {
      type: [Number, String]
    },
    checkShow: {
      type: Boolean,
      default: false
    },
    organize: {
      type: String,
      default: '责任部门'
    }
  },
  computed: {
    indexOneArr() {
      const systemInfo = getStorage('systemInfo')
      if (systemInfo && systemInfo.length) {
        const temp = systemInfo.filter(item => item.code === this.$config.xtWZ)
        if (temp && temp.length) {
          return temp[0].dictValDTOList
        }
      }
      return []
    }
  },
  data() {
    return {
      // 搜索相关参数
      searchFrom: {
        indexOne: '',
        indexTwo: '',
        indexThree: '',
        name: '',
        belongPart: ''
      },
      // 责任部门
      organizeArr: []
    }
  },
  methods: {
    // 搜索
    search() {
      this.$emit('search', this.searchFrom)
    },
    // 返回上一级页面
    goBack() {
      this.$router.go(-1)
    },
    // 获取责任部门下拉数据
    getOrganize() {
      getAllOrganize()
        .then(res => {
          this.organizeArr = res || []
        })
        .catch()
    },
    handleCheck() {
      this.$emit('check', 'check')
    },
    downloadTemplate() {
      window.open('质控点批量导入模板.xlsx', '_self')
    },
    // 显示导入质控点弹窗
    showTemplateDialog() {
      this.$emit('showTemplateDialog')
    }
  },
  created() {
    // 仅在 模板管理 模块显示 导入质控点按钮和导入质控点模板下载
    // if (this.$route.query.levelType === 'XT_WH_ZY') {
    //   this.isShowTemplateButton = true
    // }
    // 查询类型
    // this.levelType = this.$route.query.levelType || ''
    // console.log(this.levelType)
    // console.log(this.$route)
    // console.log(this.levelType)
    this.getOrganize()
  }
  /*  watch: {
    $route: {
      handler(val) {
        console.log(val)
        console.log('leveList 路径改变')
        console.log('-----------')
      },
      deep: true,
      immediate: true
    }
  } */
}
</script>

<style lang="scss" scoped>
.search-from {
  /deep/ .el-form {
    .el-form-item--small.el-form-item {
      margin-bottom: 10px;
      margin-right: 18px;
      &:last-child {
        margin-right: 0;
      }
    }
    .el-form-item__label {
      padding: 0;
    }
  }
}
</style>
